package bainuo;

import com.yonyou.iuap.open.builder.OpenServiceBuilder;
import com.yonyou.iuap.open.http.model.HttpResponse;
import com.yonyou.iuap.open.invoke.InputParam;
import com.yonyou.iuap.open.invoke.Invoke;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

public class testGetAccassToken {
    public static void main(String[] args) {
        testEnv2();
    }

    /**
     * 自建应用调用openapi
     */
    @Test
    public static void testEnv2() {
        Map<String, Object> map = new HashMap<>();
        map.put("pageIndex", 1);
        map.put("pageSize", 10);
        Map<String, Object> simple = new HashMap<>();
        simple.put("ecProcessStatus", "ALL");
        map.put("simple", simple);
        //传入appKey和环境信息，主要用于获取accessToken
        OpenServiceBuilder openServiceBuilder = new OpenServiceBuilder()
                .setAppKey("bb79e444132a4048987b3928b1ffc040") //自建应用的appKey
                .setAppSecret("14b111022ac4eb6cf84df3e55e2c0f49f8d2cf8a") //自建应用的appSecret
                .setEnv("https://srm.bestcomm.cn:11443"); //环境信息，传入统一域名即可
        //传入openapi的相对地址和请求参数信息
        InputParam inputParam = new InputParam()
                .setUrl("/yonbip/cpu/purchase/list")
                .setBody(map)
                .setContentType("application/json")
                .setMethod("POST");
        try {
            //获取opanapi调用结果
            HttpResponse result = Invoke.getResult(openServiceBuilder, inputParam);
            System.out.println(result.getStatusCode() + "===" + result.getResult());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
